using System.Collections.Generic;
using System.Runtime.Serialization;
using VideoStore.Common.Response.Interface;

namespace VideoStore.Common.Response
{
    /// <summary>
    /// Provides a minimal implementation of the IResponse interface.
    /// Works with services providing a wrapper for responses to be transferred 
    /// accross the wire.
    /// </summary>
    [DataContract]
    public class VoidResponse : IResponse
    {
        #region Fields

        private List<Error> errors = new List<Error>();
        private List<Message> messages = new List<Message>();

        /// <summary>
        /// Collection of errors produced by the calling service
        /// </summary>
        [DataMember]
        public List<Error> Errors
        {
            get
            {
                if (errors == null)
                {
                    errors = new List<Error>();
                }
                return errors;
            }
            protected set { errors = value; }
        }

        /// <summary>
        /// Collection of messages produced by the calling service
        /// </summary>
        [DataMember]
        public List<Message> Messages
        {
            get
            {
                if (messages == null)
                {
                    messages = new List<Message>();
                }
                return messages;
            }
            protected set { messages = value; }
        }

        /// <summary>
        /// The response was successful from the calling service.
        /// </summary>
        [DataMember]
        public bool IsSuccessful { get; set; }

        #endregion
    }

    /// <summary>
    /// Provides a minimal implementation of the typed IResponse interface.
    /// Works with services providing a wrapper for responses to be transferred 
    /// accross the wire.
    /// </summary>
    [DataContract]
    public class Response<T> : VoidResponse, IResponse<T>
    {
        #region Fields

        /// <summary>
        /// Response object. Contains the actual response from the requested service.
        /// </summary>
        [DataMember]
        public T ResponseObject { get; set; }

        #endregion
    }
}